import { BadRequestException, Body, Controller, Post, UseGuards } from '@nestjs/common';
import { ApiBearerAuth, ApiOkResponse, ApiOperation, ApiTags, } from '@nestjs/swagger';
import { SendMineMobileVcodeDto, SendMobileVcodeDto } from './vcode.dto';
import { VcodeService } from './vcode.service';
import { SendMobileVcodeResult } from "@/module/vcode/vcode.result";
import { UserAuthGuard } from "@/common/auth/user-auth.guard";
import { User } from "@/common/auth/user.decorator";
import { UserModel } from "@/module/user/user.model";

@Controller('/v1/vcode')
@ApiTags('Vcode')
@ApiBearerAuth()
export class VcodeV1Controller {
  constructor(private readonly vcodeService: VcodeService) {
  }

  /*@Post('/email')
  @ApiOperation({ summary: '发送邮箱验证码' })
  @ApiOkResponse({ type: SendEmailVcodeResult })
  async sendEmailVcode(
    @Body() body: SendEmailVcodeDto,
  ): Promise<SendEmailVcodeResult> {
    const vcodeKey = await this.vcodeService.sendEmailVcode(body);
    return { vcodeKey };
  }*/

  @Post('/mobile')
  @ApiOperation({ summary: '发送手机验证码' })
  @ApiOkResponse({ type: SendMobileVcodeResult })
  async sendMobileVcode(
    @Body() body: SendMobileVcodeDto,
  ): Promise<SendMobileVcodeResult> {
    const vcodeKey = await this.vcodeService.sendMobileVcode(body);
    return { vcodeKey };
  }

  @Post('/mobile/mine')
  @ApiOperation({ summary: '发送手机验证码给自己' })
  @ApiOkResponse({ type: SendMobileVcodeResult })
  @UseGuards(UserAuthGuard)
  async sendMineMobileVcode(
    @Body() body: SendMineMobileVcodeDto,
    @User() user: UserModel,
  ): Promise<SendMobileVcodeResult> {
    const vcodeKey = await this.vcodeService.sendMineMobileVcode(body, user.mobile);
    return { vcodeKey };
  }
}
